<?php

namespace App\Http\Controllers\Receivemoney;

use App\Http\Controllers\BaseController;
use App\Models\Receivemoney\Receipt;
use Illuminate\Http\Request;

/**
 * 收款单管理 业务端
 */
class ReceiptController extends BaseController
{
    /**
     * 列表
     */
    public function getlist(Request $request)
    {
        $memberinfo = $this->mangerinfo;
        $isgetall = $request->isgetall ?? 0;
        $list = Receipt::getList($request, $memberinfo, $isgetall);
        if ($list['list']) {
            foreach ($list['list'] as $key => $value) {
                $list['list'][$key]['amount'] = $value['amount'] / 100;
            }
        }
        return response()->json(['code' => '000', 'msg' => '操作成功', 'data' => $list]);
    }

    /**
     * 详情
     */
    public function getone(Request $request)
    {
        $id = $request->id ?? 0;
        $one = Receipt::getone($id);
        if (!$one) {
            return response()->json(['code' => '001', 'msg' => '收款单不存在']);
        } else {
            $one = $one->toArray();
            $one[0]['amount'] = $one[0]['amount'] / 100;
            return response()->json(['code' => '000', 'msg' => '操作成功', 'data' => $one]);
        }
    }
}
